import Vue from 'vue'
import Router from 'vue-router'
import Login from '../views/Login.vue'
import Home from '../views/Home.vue'
import Welcome from '../components/welcome.vue'
import Users from '../components/users.vue'
import Hotel from '../components/hotel.vue'
import Room from '../components/room.vue'
import Order from '../components/order.vue'
import HotelHome from '../views/HotelHome.vue'
import UserHome from '../views/UserHome.vue'
import HotelRoom from '../components/hotelroom.vue'
import HotelType from '../components/hoteltype.vue'
import HotelOrder from '../components/hotelorder.vue'
import HotelBill from '../components/hotelbill.vue'
import HotelBill2 from '../components/hotelbill2.vue'
import UserOrder from '../components/uesrorder.vue'
import UserBill from '../components/userbill.vue'
// import Report from'../components/report.vue'

Vue.use(Router)


 const router = new Router({
  routes: [
    {
      path: '/',
      name: 'Login',
      component: Login
    },
    {
      path: '/home',
      name: 'Home',
      component: Home,
      redirect: '/welcome',
      children:[{
        path:'/welcome',
        name:'Welcome',
        component: Welcome
      },
      {
        path:'/users',
        name:'Users',
        component: Users
      },
      {
        path:'/hotel',
        name:'Hotel',
        component: Hotel
      },
      {
        path:'/order',
        name:'Order',
        component: Order
      },
      {
        path:'/room',
        name:'Room',
        component: Room
      }]
    },
    {
      path: '/hotelhome',
      name: 'HomeHome',
      component: HotelHome,
      redirect: '/hotelroom',
      children:[
        {
          path:'/hotelroom',
          name:'HotelRoom',
          component:HotelRoom
        },
        {
          path:'/hoteltype',
          name:'HotelType',
          component:HotelType
        },
        {
          path:'/hotelorder',
          name:'HotelOrder',
          component: HotelOrder
        },
        {
          path:'/hotelbill',
          name:'HotelBill',
          component: HotelBill
        },
        {
          path:'/hotelbill2',
          name:'HotelBill2',
          component: HotelBill2
        },
      ]
      },
    {
      path: '/userhome',
      name: 'UserHome',
      component: UserHome,
      redirect: '/userbill',
      children:[
        {
          path:'/userorder',
          name:'UserOrder',
          component: UserOrder
        },
        {
          path:'/userbill',
          name:'UserBill',
          component: UserBill
        }
      ]
    }
  ]
})
router.beforeEach((to,from,next)=>{
  if(to.path === '/') return next()
  //获取token信息
  let token = window.sessionStorage.getItem('token')
  if(!token) return next('/')
  //表示放行
  next()
})

export default router
